<template>
  <div class="home">
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white" >
      <van-swipe-item v-for="item in bannerList" :key="item.id">
        <img :src="item.picUrl">
      </van-swipe-item>
     
    </van-swipe>
    <div class="goods">
      <p><span>商品列表</span></p>
      <div class="goods-list">
        <div class="goods-item" v-for="item in goodsList" :key="item.id" @click="gotogoods(item.id)">
          <img :src="item.pic">
          <p class="goods-title">{{item.name}}</p>
          <div class="goods-price">
            <span class="minprice">￥{{item.minPrice}}</span>
            <span class="oldprice">￥{{item.originalPrice}}</span>
            <van-button class="btn" plain type="success">购买</van-button>
          </div>
        </div>
        
      </div>
    </div>
    <TabBar></TabBar>
  </div>
</template>

<script lang="ts" setup>
import TabBar from '@/components/TabBar.vue';
import{ref} from "vue"
import request from "../../utils/request"
  import router from "../router"
  let bannerList:any=ref([])
  function getBannerlist(){
    request({
      url:"/banner/list"
    }).then((res:any)=>{
      if(res.code===0){
        bannerList.value=res.data
      }
    })
  }
  let goodsList:any=ref([])
  function getGoodslist(){
    request({
      url:"/shop/goods/list/v2",
      method:"post"
    }).then((res:any)=>{
      console.log(res)
       if(res.code===0){
        goodsList.value=res.data.result

       }
    })
  }
    getBannerlist()
    getGoodslist()
  function gotogoods(id:any){
    router.push("/goods?id="+id)
  }
</script>

<style lang="scss">
.my-swipe .van-swipe-item {
  img {
    width: 375px;
    height: 180px;
  }
}

.goods {
  >p {
    height: 50px;
    line-height: 50px;
    text-align: center;
    font-size: 16px;
    font-weight: bold;

    span:before {
      content: "";
      display: inline-block;
      width: 20px;
      height: 6px;
      background-image: url(https://v-shop.shuzp.top/v2/assets/img/line_askew.225cce63.png);
      margin-right: 15px;
    }
    span::after {
      content: "";
      display: inline-block;
      width: 20px;
      height: 6px;
      background-image: url(https://v-shop.shuzp.top/v2/assets/img/line_askew.225cce63.png);
      margin-left: 15px;
    }


  }

  .goods-list {
    display: flex;
    flex-wrap: wrap;
  }

  .goods-item {
    width: 187.5px;
    margin-bottom: 10px;
    padding: 0 7.5px;
    box-sizing: border-box;

    img {
      width: 172.5px;
      height: 172.5px;
    }

    .goods-title {
      height: 36px;
      font-size: 14px;
      overflow: hidden;
    }

    .goods-price {
      height: 24px;
    }

    .minprice {
      font-size: 18px;
      color: #1ba784;
    }

    .oldprice {
      font-size: 12px;
      text-decoration: line-through;
      color: #969799;
    }

    .btn {
      float: right;
      height: 24px;
      padding: 0 8px;
      line-height: 24px;
      font-size: 14px;
    }
  }
}
</style>
